<?php

namespace app\modules\index\services;

use app\common\services\BaseService;

/**
 * 店铺
 * Class StoreService
 * @package app\modules\index\services
 */
class StoreService extends BaseService{

    /**
     * 首页
     * @param $merchant_id
     * @return array|\yii\db\ActiveRecord[]
     */
    public static function index($merchant_id){
        $categorys = GoodsCategoryService::search($merchant_id);
        $goods = GoodsService::search($merchant_id,null);
        foreach($categorys as $k=>$v){
            foreach($goods as $kk=>$vv){
                if($v['cat_id'] == $vv['cat_id']){
                    $categorys[$k]['goods'][] = $goods[$kk];
                    unset($goods[$kk]);
                }
            }
        }
        return [
            'store'=>MerchantService::getInfoById($merchant_id),
            'activity'=>ActivityService::search($merchant_id),
            'data'=>$categorys,
        ];
    }
}